package com.app.megaprosoft.DB;

import java.sql.*;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;


public class ItemGroupMain {
	
	
	 ResultSet rs = null;
	 SQLiteDBClass myDb;
	 SQLiteDatabase db;
	 Context context;
	 private static final String TABLE_ItemGroupMain = "_ItemGroupMain";
	 
	 public Context getContext() {
		return context;
	 }

	 public void setContext(Context context) {
		this.context = context;
	 }
	private String OID,
			    UsrOpt,
			    IsActive,
			    IsDeleted,
				ItemGroupMainCode,
				ItemGroupMainDesc;
	
    public ItemGroupMain() {ItemGroupMainCode=ItemGroupMainDesc="";
    }
	
    public ItemGroupMain( 
    		String OID,
    		String UsrOpt,
    		String IsActive,
    		String IsDeleted,
    		String ItemGroupMainCode,
    		String ItemGroupMainDesc
    		)
    {
    	this.OID = OID;
    	this.UsrOpt = UsrOpt;
    	this.IsActive = IsActive;
    	this.IsDeleted = IsDeleted;
    	this.ItemGroupMainCode = ItemGroupMainCode;
    	this.ItemGroupMainDesc = ItemGroupMainDesc;
    }
	
    public String getOID() {
		return OID;
	}

	public void setOID(String oID) {
		OID = oID;
	}

	public String getUsrOpt() {
		return UsrOpt;
	}

	public void setUsrOpt(String usrOpt) {
		UsrOpt = usrOpt;
	}

	public String getIsActive() {
		return IsActive;
	}

	public void setIsActive(String isActive) {
		IsActive = isActive;
	}

	public String getIsDeleted() {
		return IsDeleted;
	}

	public void setIsDeleted(String isDeleted) {
		IsDeleted = isDeleted;
	}

	public void setItemGroupMainCode(String ItemGroupMainCode)
	{
		this.ItemGroupMainCode = ItemGroupMainCode;
	}
	public void setItemGroupMainDesc(String ItemGroupMainDesc)
	{
		this.ItemGroupMainDesc = ItemGroupMainDesc;
	}
	
	//public String getOperationType()
	//{
		//return this.OperationType;
	//}
	public String getItemGroupMainCode()
	{
		return this.ItemGroupMainCode;
	}
	public String getItemGroupMainDesc()
	{
		return this.ItemGroupMainDesc;
	}
	
	public ResultSet selectItemGroupMain(String StrItemGroupMainDesc) throws Exception {
		 Connect con = new Connect(); 
		String StrSql   = "SELECT [OID]," +
				"[LastModified]," +
				"[ModifyDate]," +
				"[ModifyTime]," +
				"[ModifiedBy]," +
				"[UserModify]," +
				"[CreatedDate]," +
				"[CreateDate]," +
				"[CreateTime]," +
				"[CreatedBy]," +
				"[UserCreate]," +
				"[IsActive]," +
				"[IsDeleted]," +
				
				"[ItemGroupMainCode]," +
				"[ItemGroupMainDesc] " +
				
				"FROM [dbo].[udfItemGroupMain]() " +
				"WHERE [IsDeleted]='0' "; 
			     	
		if (!StrItemGroupMainDesc.equals("")) {
            StrSql += "AND [ItemGroupMainDesc] LIKE '%" + StrItemGroupMainDesc + "%'";
        }
    	
		return con.selectData(StrSql);
	 }
	
	public ResultSet defineItemGroupMain() throws Exception {
		 Connect con = new Connect(); 
        String StrSql = "SELECT [OID]," +
        		"[IsActive]," +
				"[IsDeleted]," +
        		"[ItemGroupMainCode]," +
        		"[ItemGroupMainDesc] " +
        		"FROM [dbo].[udfItemGroupMain]() " +
        		"WHERE [IsDeleted]='0' " ;


        StrSql += "ORDER BY [ItemGroupMainDesc] ASC";

        return con.selectData(StrSql);
    }
	
//	 public void closeConnecttion() throws Exception {
//    	 if (conn != null) {
//             conn.close();
//         }
//    }
	 
	 public void DEFINE_ItemGroupMain() {
			rs = null;
			
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();

			try {
				rs = selectItemGroupMain("");
				while (rs.next()) {
					ContentValues Val = new ContentValues();
					Val.put("ItemGroupMainOID", rs.getString("OID"));

					Val.put("ItemGroupMainCode", rs.getString("ItemGroupMainCode"));
					Val.put("ItemGroupMainDesc", rs.getString("ItemGroupMainDesc"));

					db.insert(TABLE_ItemGroupMain, null, Val);
				}
				rs.close();
			} catch (Exception e) {
				Log.d("TABLE_ItemGroupMain", "Create Table not Successfully.");
			}
			Log.d("TABLE_ItemGroupMain", "Create Table Successfully.");
			db.close();
		}
	 
	 public String[][] SelectAll_ItemGroupMain() throws Exception{
			// TODO Auto-generated method stub
			try {
				String arrData[][] = null;
				myDb = new SQLiteDBClass(getContext());
				db = myDb.getWritableDatabase();
				String strSQL = "SELECT  ItemGroupMainOID As _id , * FROM "
						+ TABLE_ItemGroupMain + " ORDER BY ItemGroupMainCode ASC ";
				Cursor cursor = db.rawQuery(strSQL, null);
				if (cursor != null) {
					if (cursor.moveToFirst()) {
						arrData = new String[cursor.getCount()][cursor
								.getColumnCount()];
						int i = 0;
						do {
							arrData[i][0] = cursor.getString(1);
							arrData[i][1] = cursor.getString(2);
							arrData[i][2] = cursor.getString(3);
							i++;
						} while (cursor.moveToNext());
					}
				}
				cursor.close();
				return arrData;
			} catch (Exception e) {
				return null;
			}
		}

	 
	 
}
